﻿using System.Windows;
using System.Windows.Controls;
using appDataContracts;

namespace appSupplier.UserControls
{
    /// <summary>
    /// Logique d'interaction pour UCCommands.xaml
    /// </summary>
    public partial class UCOldCommands : UserControl
    {

        public UCOldCommands()
        {
            InitializeComponent();
            this.dgCommands.ItemsSource = AppWindow.supplierService.getSupplierOrders(AppWindow.supplier.SUPPLIERID);
        }

        private void dgCommands_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            if (dgCommands.SelectedItems.Count > 0)
            {
                btDetail.Visibility = Visibility.Visible;
            }
            else
            {
                btDetail.Visibility = Visibility.Hidden;
            }
        }

        private void btDetail_Click(object sender, RoutedEventArgs e)
        {
            new CommandDetailWindow((SerializedOrderLine)dgCommands.SelectedItem).ShowDialog();
        }

        private void dgCommands_MouseDoubleClick(object sender, System.Windows.Input.MouseButtonEventArgs e)
        {
            btDetail_Click(sender, e);
        }

        private void btRefresh_Click(object sender, RoutedEventArgs e)
        {
            this.dgCommands.ItemsSource = AppWindow.supplierService.getSupplierOrders(AppWindow.supplier.SUPPLIERID);
        }
    }
}
